﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<link href="~/Content/js/select2/select2.min.css" rel="stylesheet" />
<link href="~/Content/css/daterangepicker.min.css" rel="stylesheet" />
<style>

    #gridPager_left {
        text-align:right;
    }

    .topPanel .search .input-group {
        float: left;
        margin-right: 0.5%;
        width: 16%;
        box-sizing: border-box;
        line-height: 29px;
    }

    tbody > tr > td[aria-describedby="gridList_cb"] {
        vertical-align: middle;
    }

    tbody > tr > td > div.ckbox {
        height: 18px;
    }

</style>

<script>

    function showCate(cellValue, options, rowObject) {
        return "<i class=\"fa fa-" + (rowObject.weight == 0 ? "star-o":(rowObject.weight == 1 ? "star-half-o" : "star")) + "\"></i>" + rowObject.cate;
    }

    function showState(cellValue, options, rowObject) {
        return cellValue == 0 ? "新增":(cellValue == 1 ? "已处理" : "无效");
    }

    function showOp(cellValue, options, rowObject) {
        if (rowObject.state == 0) {
            return "<a href=\"javascript:void(0);\" onclick=\"dealMsg('" + rowObject.id + "')\">处理</a>";
        }
        return "";
    }

    function dealMsg(id) {
            $.loading(true);
            $.getJSON("/WorkFlow/WorkFlow/ProcessMsg?id=" + id, function (rsp) {
                $.loading(false);
                if (rsp.state) {
                    var size = ["800px", "700px"];
                    if (rsp.node.size) {
                        size = rsp.node.size.split(",");
                        size[0] += "px";
                        size[1] += "px";
                    }
                    top.layer.open({
                        id: "ProcessMsg",
                        type: 2,
                        shade: 0.3,
                        title: rsp.node.name,
                        fix: false,
                        area: size,
                        content: "/WorkFlow/WorkFlow/Process?id=" + rsp.msg,
                        btn: ['提交', '关闭'],
                        btnclass: ['btn btn-primary', 'btn btn-danger'],
                        yes: function (index) {
                            top.frames["ProcessMsg"].process(function (pr) {
                                if (pr.state) {
                                    top.layer.close(index);
                                    top.layer.alert("处理成功", {
                                        icon: "fa-check-circle",
                                        title: "处理结果",
                                        btn: ['确认'],
                                        btnclass: ['btn btn-primary']
                                    }, gridList);
                                }
                                else if (pr.msg) {
                                    top.layer.alert(pr.msg, {
                                        icon: "fa-times-circle",
                                        title: "处理结果",
                                        btn: ['确认'],
                                        btnclass: ['btn btn-primary']
                                    });
                                }
                                else {
                                    top.layer.close(index);
                                    loadMyMsg();

                                }
                            });
                        }, cancel: function () {
                            return true;
                        }
                    });
                }
                else {
                    top.layer.msg(rsp.msg, { icon: "fa-times-circle" }, gridList);
                }
            });
    }

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/WorkFlow/WorkFlow/SearchMyMsg",
            height: $(window).height() - 207,
            mtype: "POST",
            shrinkToFit: false,
            colModel: [
                { label: '', name: 'id', width: 0, hidden: true, key: true },
                @{
                    var loginUser = DJY.Code.OperatorProvider.GetCurrent();
                    if(loginUser != null && loginUser.IsSystem)
                    {
                        <text>{ label: '处理人', name: 'operateMan', sortable: false,width: 100, align: 'left' },</text>
                    }
                }
                { label: '流程', name: 'cate', sortable: false,width: 100, align: 'left', formatter: showCate},
                { label: '节点', name: 'msg', sortable: false,width: 150, align: 'left' },
                { label: '状态', name: 'state', sortable: false, width: 80, align: 'left', formatter: showState },
                { label: '时间', name: 'time', sortable: false, width: 150, align: 'left' },
                { label: '备注', name: 'remark', sortable: false, width: 150, align: 'left' },
                { label: '操作', name: '_op', sortable: false, width: 100,align: 'left', formatter: showOp },
            ],
            pager: "#gridPager",
            viewrecords: true,
            altRows: false,
            multiselect: false,
            multiboxonly: false,
            userDataOnFooter: false,
            footerrow: false,
            sortorder: "desc",
            beforeRequest: function () {
                var para = {};
                para.instanceId = $("#txtInstanceId").val();
                para.state = $("#txtState").val();
                para.weight = $("#txtWeight").val();
                para.msg = $("#txtMsg").val();
                $(this).jqGrid("setGridParam", {
                    postData: para
                });
            },
            beforeProcessing: function (data, status, xhr) {
                if (data.state == "error" && data.message == "NOT_LOGIN") {
                    top.window.location.href = "/Login/Index?url=" + location.href;
                    return false;
                }
            },
            onSelectRow: null
        });
    }

    $(function () {
        $("#btn_search").click(function () {
            $("#gridList").trigger('reloadGrid');
        });
        gridList();
    });
</script>

<div class="topPanel" style="height:unset;line-height:40px;padding:5px;display:flex;">
    <div class="search" style="flex:1;padding-left:0px;">
        <div class="input-group">
            <input id="txtInstanceId" type="text" class="form-control" placeholder="流程实例">
        </div>
        <div class="input-group" style="width:100px;">
            <select id="txtState" class="form-control">
                <option value="">--状态--</option>
                <option value="0">新增</option>
                <option value="1">已处理</option>
                <option value="2">无效</option>
            </select>
        </div>
        <div class="input-group" style="width:130px;">
            <select id="txtWeight" class="form-control">
                <option value="">--紧急程度--</option>
                <option value="0">一般</option>
                <option value="1">重要</option>
                <option value="2">紧急</option>
            </select>
        </div>
        <div class="input-group">
            <input id="txtMsg" type="text" class="form-control" placeholder="信息">
        </div>
        <div class="input-group" style="display:inline-block;">
            <button id="btn_search" type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
        </div>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
